<template>
	<view>
		<van-action-sheet :show="props.show" @close="onClose" :actions="kdList" @select="onSelected">
		</van-action-sheet>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		defineProps,
		defineEmits,
		onMounted
	} from 'vue'
	import {
		getKdList
	} from '@/api/index.js'
	const props = defineProps(['show']);
	const emits = defineEmits(['close', 'onSelected']);
	const kd = ref('');
	const kdList = ref([])
	const onClose = () => {
		emits('close')
	}

	const getKd = async () => {
		try {
			let res = await getKdList();
			kdList.value = Object.values(res.data).map(item => {
				return {
					name: item
				}
			}, []);
		} catch (e) {
			//TODO handle the exception
		}
	}

	const onSelected = (e) => {
		kd.value = e.detail.name
		emits('onSelected', kd.value)
	}

	onMounted(() => {
		getKd()
	})
</script>

<style>

</style>